﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApp3
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            double areaSum = 0;
            Random ran = new Random();
            for (int i=0; i < 10;i++)
            {

                int name = ran.Next(1, 4);

                double width = ran.NextDouble() * 10;

                double height = ran.NextDouble() * 10;

                double side = ran.NextDouble() * 10;

                double radium = ran.NextDouble() * 10;


                Shape shape = Factory.GetShape(name, width, height, side, radium);
                if (shape != null)
                {
                 
                    areaSum += shape.Area();
                  
                }
            }
        
            textBox1.Text = Convert.ToString(areaSum);
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }
    }
    public abstract class Shape
    {
        public abstract double Area();
        public abstract string isLegal();

    }
    public class Rectangle : Shape
    {
        double width;
        double height;
         public Rectangle(double width,double height)
        {
            this.width = width;
            this.height = height;
        }
        public override double Area()
        {
            return width * height;
        }
        public override string isLegal()
        {
            if (width != height && width > 0 && height > 0)
            {
                return "rectangle";

            }
            else return "erro";
        }
    }

    public class Square : Shape
    {
        double side;
        public Square(double side)
        {
            this.side = side;
        }
        public override double Area()
        {
            return side * side;
        }
        public override string isLegal()
        {
            if (side > 0)
            {
                return "square";
            }
            else return "erro";
        }
    }
    public class Circle : Shape
    {
        double radium;
       public Circle(double radium)
        {
            this.radium = radium;
        }
        public override double Area()
        {
            return Math.PI * radium * radium;
        }
        public override string isLegal()
        {
            if (radium > 0)
            {
                return "circle";
            }
            else return "erro";
        }

    }
    class Factory
    {
        public static Shape GetShape(int name, double width, double height, double side, double radium)
        {
            switch (name)
            {
                case 1: return new Rectangle(width, height);
                case 2: return new Square(side);
                case 3: return new Circle(radium);
                default:
                    return null;
            }
        }
    }
    
}
